{include file="header/index" /}
<div class="container bgwhite">
	<h2 class="container-title ">修改工程人员</h2>
	<p class="mt30 fs14 col-333">主要信息</p>

	<form id="form" enctype="multipart/form-data">
		<input type="hidden" name="engineers_id" value="{$data.engineers_id}">
		<p class="mt20 mb20">
			<label class="addEnginerr-title">姓名</label>
			<input id="name" class="addEnginerr-input" type="text" value="{$data.engineers_name}" name="engineers_name"  placeholder="请输入真实姓名"/>
			<i class="col-red">*</i>
		</p>

		<p class="mt20 mb20 clearfix">
			<label class="addEnginerr-title mt40">头像</label>
			<span class="head_img_btn">更改头像
				<!--<input class="fl" type="file" value="" name=""  placeholder=""/>-->
				<input type="file" name="avatar_img" id="avatar_img" class="webuploader-element-invisible" multiple="multiple" onchange="uploadFile()" accept="image/jpg,image/jpeg,image/png">
			</span>
			<img class="fl head_img" id="img" src="{if condition='((isset($data)))'}{:Config('IMAGES_PATH')}{$data.avatar_img}{else /}__IMG__/head_default.gif{/if}" >
		</p>

		<p class="mt20 mb20">
			<label class="addEnginerr-title">员工编号</label>
			{if condition='((isset($data)))'}
			<div class="mt25">{$data.engineers_number}
			<input type="hidden" id="engineers_number" name="engineers_number" value="{$data.engineers_number}"/></div>
			{else /}{/if}
		</p>

		<p class="mt20 mb20">
			<label class="addEnginerr-title">联系电话</label>
			<input id="tel" class="addEnginerr-input" type="text" name="engineers_phone" placeholder="请输入电话号码" maxlength="11" value="{$data.engineers_phone}" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();"/>
			<i class="col-red">* 将作为登录账户</i>
		</p>

		<p class="mt20 mb20">
			<label class="addEnginerr-title">登录密码</label>
			<input id="password" class="addEnginerr-input" type="password" name="engineers_password" placeholder="输入登录密码(不填默认为123456)" maxlength="11" onkeyup="value=value.replace(/[^\d]/g,'')"/>
			<i class="col-red">*</i>
		</p>

		<p class="mt20 mb20">
			<label class="addEnginerr-title">身份证号</label>
			<input id="IDnum" class="addEnginerr-input" type="text" value="{$data.engineers_idcard}" name="engineers_idcard" placeholder="请输入身份证号码" maxlength="18"/>
			<i class="col-red">*</i>
		</p>
		<p class="mt20 mb20 ">
			<label class="addEnginerr-title">生日</label>
			<input type="text" name="birthday" readonly class="addEnginerr-input form_datetime" placeholder="请选择时间" value="{$data.birthday}">
			<i class="col-red">*</i>
		</p>

		<p class="mt20 mb20">
			<label class="addEnginerr-title">账户状态</label>
			<select name="engineers_status" class="addEnginerr-select">
				<option value="2" {if condition='((isset($data)) AND ($data.engineers_status == 2))'}selected{else /}{/if}>正常</option>
				<option value="1" {if condition='((isset($data)) AND ($data.engineers_status == 1))'}selected{else /}{/if}>冻结</option>
			</select>
		</p>

		<p class="mt20 mb20">
			<label class="addEnginerr-title">员工所属管理区域</label>
			<select class="addEnginerr-select" id="operation" onchange="changeId()">
				<option value="">选择运营中心</option>
					{volist name="operationData" id="k"}
				<option value="{$k.o_id}" {if condition='((isset($o_id)) AND ($k.o_id == $o_id))'}selected{else /}{/if}>{$k.company_name}</option>
					{/volist}

			</select>

			<select class="addEnginerr-select" id="administrative_id" name="administrative_id" >
				<option value="">选择行政区域</option>
				{volist name="adminData" id="k"}
				<option value="{$k.a_id}" {if condition='((isset($a_id)) AND ($k.a_id == $a_id))'}selected{else /}{/if}>{$k.company_name}</option>
				{/volist}
			</select>
		</p>

		<p class="mt20 mb20">
			<label class="addEnginerr-title">家庭地址</label>
			<input id="addressDetail" class="addEnginerr-input" type="text" value="{$data.engineers_address}" name="engineers_address" placeholder="请输入详细地址"/>
			<i class="col-red">*</i>
		</p>

		<p class="mt20 mb20 relative">
			<label class="addEnginerr-title">备注</label>
			<textarea class="addEnginerr-textarea" maxlength="500" id="note" name="note">{$data.note}</textarea>
			<span class="absolute txtNum_tis">500字以内</span>
		</p>

		<p class="engineer-Btn">
			<button class="engineer-PreBtn" id="but" type="button">保存</button>
			<a href="javascript:(0)" class="engineer-RuterBtn" onclick="window.history.go(-1);">返回</a>
		</p>
	</form>

</div>
<script>
    //日期选择
    $(".form_datetime").datetimepicker({
        format: "yyyy-mm-dd",
        autoclose: true,
        minView: "month",
        todayBtn: true,
        pickerPosition: "bottom-left",
        language: 'cn'
    });

    /**
     * 图片显示
     */
    function uploadFile() {
        var file = document.getElementById("avatar_img").files[0];
        var reader = new FileReader();
        reader.onload = function(e) {
            img.src = this.result;
        };
        reader.readAsDataURL(file); //Base64
    }

     // 获取表单数据
    $("#but").click(function () {
        var formData = new FormData($( "#form" )[0]);
        $.ajax({
            url:  "{:url('Engineer/doedit')}",  /*这是处理文件上传的servlet*/
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            dataType : 'json',
            success: function (data) {
                if (data.status == 0) {
                    top.layer.msg(data.message, {icon: 2,time: 2000});
                    return false;
                }else{
                    top.layer.msg(data.message, {icon: 1,time: 2000},function () {history.back();});
                    return false;
				}

            },error: function (data) {

            }
        });
    });
    //行政区域选择
    function changeId() {
        console.log(1)
        var id=$('#operation').val();
		$.getJSON("{:url('engineer/getAdmin')}",{id:id},function (data) {
			$('#administrative_id').html('');
			var str = '<option value="">选择行政区域</option>';
			$.each(data,function(k,v){
				str += '<option value="' + v.a_id + '">' + v.company_name + '</option>';
			});
			$("#administrative_id").html(str);
        });
    }

    // 三级联动
	$(function(){
	    // 发送ajax请求 ，获取所有的省
		$.getJSON("{:url('admin/Three/province')}",{},function(data){
		 	$("#_province").html('');
            var str = '<option value="0">--选择省--</option>';
            $.each(data,function(k,v){
                str += '<option value="' + v.id + '">' + v.area_name + '</option>';
			});
            $("#_province").html(str);
		});
	});
	// 根据选中的省获取对应的市
	function showcity(){
	    // 获取选中省对应的id 值
	    var id = $('#_province option:selected') .val();
        var province_name = $('#_province option:selected') .html();
	    $("input[name='province']").val(province_name);
	    // 发送ajax请求 获取对应的市
		$.getJSON("{:url('admin/Three/city')}",{parent_id:id},function(data){
			$("#_city").html('');
			var str = '<option value="0">--选择市--</option>';
			$.each(data,function(k,v){
			   str += '<option value="' + v.id + '">' + v.area_name + '</option>';
			});
			$("#_city").html(str);
		});
	}

	// 根据选中的市获取对应的区县
	function showarea() {
	    // 获取选中市对应的id 值
		var id = $('#_city option:selected').val();
		var city_name = $('#_city option:selected') .html();
		$("input[name='city']").val(city_name);

		// 发送ajax请求 获取对应的区县
		$.getJSON("{:url('admin/Three/areas')}",{city_id:id},function(data){
		   	$("#_area").html('');
		   	var str = '<option value="0">--选择区/县--</option>';
		   	$.each(data,function(k,v){
		   	   str += '<option value="' + v.id + '">' + v.area_name + '</option>';
			});
		   	$("#_area").html(str);
		});
	}

	function showareas(){
        var city_name = $('#_area option:selected') .html();
        $("input[name='area']").val(city_name);
	}


</script>
</body>
</html>
